package com.lczyfz.istep.common.utils.domain;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * <p>Created by Charkey on 2017/4/28.</p>
 */
public class SubDomainServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.getRequestDispatcher("/index.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Demo demo = new Demo();
        String subDomain = req.getParameter("subdomain");
        String vhostPort = req.getParameter("vhostPort");
        String vhostHost = req.getParameter("vhostHost");
        if (subDomain == null || subDomain.equals("")) {
            req.getRequestDispatcher("/index.jsp").forward(req, resp);
        }
        demo.createSubDomain(subDomain, vhostHost,vhostPort);
        resp.setCharacterEncoding("UTF-8");
        resp.setHeader("content-type","text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        out.write("SUCCESS! 请访问：" + subDomain + ".simastudio.cn");
    }
}
